<template>
    <div class="checkTel">
        <van-nav-bar title="标题" class="navbar" left-text="返回" left-arrow @click-left="onClickLeft" />
        <div class="content">
            <van-field v-model="tel" name="手机号" placeholder="手机号" />
            <div style="margin: 16px;">
                <van-button round block type="primary" :disabled="!flag" class="custom_btn" @click="checkPhone">
                    提交
                </van-button>
            </div>
        </div>
    </div>
</template>

<script>
import { doCheckphone } from '@/apis/user/index'
export default {
    data() {
        return {
            tel: "18080807088"
        }
    },
    computed: {
        flag() {
            return /^1[35789]\d{9}$/.test(this.tel)
        }
    },
    methods: {
        onClickLeft() {
            this.$router.back()
        },
        checkPhone() {
            doCheckphone({ tel: this.tel }).then(res => {
                if (res.data.code == '10005') {
                    return showToast('手机号已经被注册');
                }
                // 200 
                localStorage.setItem("tel",this.tel);
                this.$router.push("/register/msg")
            })
        }
    }
}
</script>

<style scoped>
.custom_btn {
    background: linear-gradient(to right, red, orange)
}
.navbar{
    color: rebeccapurple;
}
</style>